﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using LangMauViet.Models.Entity;
using LangMauViet.Models.Service;

namespace LangMauViet.Controllers
{
    public class CategoryController : Controller
    {
        //
        // GET: /Category/

        public ActionResult Index()
        {
            return View();
        }
        
        [HttpGet]
        public ActionResult ImageByCategory(long? id, int hotpage = 1, int newpage = 1)
        {
            ImageService iservice = new ImageService();
            List<Images> ilistHot = iservice.GetImages(0, 1, 4 * hotpage - 3, 4 * hotpage);
            List<Images> ilistNew = iservice.GetImages(0, 0, 4 * newpage - 3, 4 * newpage);
            int totalRecord = 0;
            List<Images> totalImage = iservice.GetImages(0, 0, 0, 0);
            totalRecord = totalImage.Count;
            List<Images> iList = null;
            List<Images> iList2 = null;
            if (id != null && id != 0)
            {
                iList = iservice.GetImages(id, 1, 4 * hotpage - 3, 4 * hotpage);
                iList2 = iservice.GetImages(id, 0, 4 * newpage - 3, 4 * newpage);
                List<Images> totalImage2 = iservice.GetImages(id, 0, 0, 0);
                totalRecord = totalImage2.Count;
            }
            CategoryService cs = new CategoryService();
            List<HotItem> lhot = cs.GetHotItem(1);
            ViewData["hotImage"] = lhot;
            ViewData["iListHot"] = ilistHot;
            ViewData["iListNew"] = ilistNew;
            ViewData["iList"] = iList;
            ViewData["iList2"] = iList2;
            ViewBag.totalRecord = totalRecord;
            ViewBag.cateId = id;
            ViewBag.hotpage = hotpage;
            ViewBag.newpage = newpage;

            //WEB

            List<Images> vlistImageXemNhieu = iservice.GetImages(0, 1, 0, 20); //1: download
            ViewData["vlistImageXemNhieu"] = vlistImageXemNhieu;
            List<Images> vlistImageNewWeb = iservice.GetImages(0, 0, 0, 7); //0: crate date
            ViewData["vlistImageNewWeb"] = vlistImageNewWeb;
            List<Images> vlistNoibat = iservice.GetImages(0, 2, 0, 6); //3: position ( o hiểu là gì)
            ViewData["listImageNoibat"] = vlistNoibat;

            int totalRecordWeb = 0;
            totalRecordWeb = totalImage.Count;
            List<Images> nListWeb = null;
            List<Images> nlistHotWeb = iservice.GetImages(0, 1, 24 * hotpage - 24, 24 * hotpage); //1: download

            if (id != null && id != 0)
            {
                nListWeb = iservice.GetImages(id, 1, 24 * hotpage - 24, 24 * hotpage);
                List<Images> totalNews2 = iservice.GetImages(id, 0, 0, 0);
                totalRecordWeb = totalNews2.Count;
            }
            ViewData["nlistHotWeb"] = nlistHotWeb;
            ViewData["nListWeb"] = nListWeb;
            ViewBag.totalRecordWeb = totalRecordWeb;

            return View();
        }
        [HttpGet]
        public ActionResult ImageLoadMore(int hotpage = 1)
        {
            ImageService iservice = new ImageService();

            int totalRecord = 0;
            List<Images> totalNews = iservice.GetImages(0, 0, 0, 0);
            totalRecord = totalNews.Count;

            CategoryService cs = new CategoryService();

            ViewBag.totalRecord = totalRecord;

            ViewBag.hotpage = hotpage;



            //WEB

            int totalRecordWeb = 0;
            totalRecordWeb = totalNews.Count;

            List<Images> ilistHotWeb = iservice.GetImages(0, 1, 24 * hotpage - 24, 24 * hotpage); //1: download

            ViewData["ilistHotWeb"] = ilistHotWeb;

            ViewBag.totalRecordWeb = totalRecordWeb;
            return View();
        }
        [HttpGet]
        public ActionResult VideoByCategory(long? id, int hotpage = 1, int newpage = 1)
        {
            VideoService vservice = new VideoService();
            List<Video> vlistHot = vservice.GetVideo(0, 1, 4 * hotpage - 3, 4 * hotpage); //1: download
            List<Video> vlistNew = vservice.GetVideo(0, 0, 4 * newpage - 3, 4 * newpage); //0: moi nhat
            int totalRecord = 0;
            List<Video> totalVideo = vservice.GetVideo(0, 0, 0, 0);
            totalRecord = totalVideo.Count;
            List<Video> vList = null;
            List<Video> vList2 = null;
            if (id != null && id != 0)
            {
                vList = vservice.GetVideo(id, 1, 4 * hotpage - 3, 4 * hotpage);
                vList2 = vservice.GetVideo(id, 0, 4 * newpage - 3, 4 * newpage);
                List<Video> totalVideo2 = vservice.GetVideo(id, 0, 0, 0);
                totalRecord = totalVideo2.Count;
            }
            CategoryService cs = new CategoryService();
            List<HotItem> lhot = cs.GetHotItem(9);
            ViewData["hotVideo"] = lhot;
            ViewData["vListHot"] = vlistHot;
            ViewData["vListNew"] = vlistNew;
            ViewData["vList"] = vList;
            ViewData["vList2"] = vList2;
            ViewBag.totalRecord = totalRecord;
            ViewBag.cateId = id;
            ViewBag.hotpage = hotpage;
            ViewBag.newpage = newpage;


            //WEB

            List<Video> vlistVideoXemNhieu = vservice.GetVideo(0, 1, 0, 20); //1: download
            ViewData["vlistVideoXemNhieu"] = vlistVideoXemNhieu;
            List<Video> vlistVideoNewWeb = vservice.GetVideo(0, 0, 0, 7); //0: crate date
            ViewData["vlistVideoNewWeb"] = vlistVideoNewWeb;
            List<Video> vlistNoibat = vservice.GetVideo(0, 2, 0, 6); //3: position ( o hiểu là gì)
            ViewData["listVideoNoibat"] = vlistNoibat;

            int totalRecordWeb = 0;
            totalRecordWeb = totalVideo.Count;
            List<Video> nListWeb = null;
            List<Video> nlistHotWeb = vservice.GetVideo(0, 1, 24 * hotpage - 24, 24 * hotpage); //1: download

            if (id != null && id != 0)
            {
                nListWeb = vservice.GetVideo(id, 1, 24 * hotpage - 24, 24 * hotpage);
                List<Video> totalNews2 = vservice.GetVideo(id, 0, 0, 0);
                totalRecordWeb = totalNews2.Count;
            }
            ViewData["nlistHotWeb"] = nlistHotWeb;
            ViewData["nListWeb"] = nListWeb;
            ViewBag.totalRecordWeb = totalRecordWeb;
            return View();
        }

        [HttpGet]
        public ActionResult VideoLoadMore(int hotpage = 1)
        {
            VideoService vservice = new VideoService();
            
            int totalRecord = 0;
            List<Video> totalVideo = vservice.GetVideo(0, 0, 0, 0);
            totalRecord = totalVideo.Count;
            
            CategoryService cs = new CategoryService();
            
            ViewBag.totalRecord = totalRecord;
            
            ViewBag.hotpage = hotpage;
            


            //WEB

           int totalRecordWeb = 0;
            totalRecordWeb = totalVideo.Count;
            
            List<Video> nlistHotWeb = vservice.GetVideo(0, 1, 24 * hotpage - 24, 24 * hotpage); //1: download

            ViewData["nlistHotWeb"] = nlistHotWeb;
           
            ViewBag.totalRecordWeb = totalRecordWeb;
            return View();
        }
        [HttpGet]
        public ActionResult NewsByCategory(long? id, int hotpage = 1, int newpage = 1)
        {
            NewsService nservice = new NewsService();
            List<News> nlistHot = nservice.GetNews(0, 1, 4 * hotpage - 3, 4 * hotpage); //1: download
            List<News> nlistNew = nservice.GetNews(0, 0, 4 * newpage - 3, 4 * newpage); //0: moi nhat
            int totalRecord = 0;
            List<News> totalNews = nservice.GetNews(0, 0, 0, 0);
            totalRecord = totalNews.Count;
            //List<News> nList = nservice.GetNews(id,0,1,10);
            List<News> nList = null;
            List<News> nList2 = null;
            if (id != null && id != 0)
            {
                nList = nservice.GetNews(id, 1, 4 * hotpage - 3, 4 * hotpage);
                nList2 = nservice.GetNews(id, 0, 4 * newpage - 3, 4 * newpage);
                List<News> totalNews2 = nservice.GetNews(id, 0, 0, 0);
                totalRecord = totalNews2.Count;
            }
            CategoryService cs = new CategoryService();
            List<HotItem> lhot = cs.GetHotItem(3);
            ViewData["hotNews"] = lhot;
            ViewData["nListHot"] = nlistHot;
            ViewData["nListNew"] = nlistNew;
            ViewData["nList"] = nList;
            ViewData["nList2"] = nList2;
            ViewBag.totalRecord = totalRecord;
            ViewBag.cateId = id;
            ViewBag.hotpage = hotpage;
            ViewBag.newpage = newpage;
          
            //ViewData["nList"] = nList;


            //WEB
            NewsService ns = new NewsService();
            List<News> vlistNewsXemNhieu = ns.GetNews(0, 1, 0, 20); //1: download
            ViewData["vlistNewsXemNhieu"] = vlistNewsXemNhieu;
            List<News> vlistNewsNewWeb = ns.GetNews(0, 0, 0, 7); //0: crate date
            ViewData["vlistNewsNewWeb"] = vlistNewsNewWeb;
            List<News> vlistNoibat = ns.GetNews(0, 2, 0, 6); //3: position ( éo hiểu là gì)
            ViewData["listNewsNoibat"] = vlistNoibat;

            int totalRecordWeb=0;
            totalRecordWeb = totalNews.Count;
            List<News> nListWeb = null;
            List<News> nlistHotWeb = nservice.GetNews(0, 1, 24 * hotpage - 24, 24 * hotpage); //1: download

            if (id != null && id != 0)
            {
                nListWeb = nservice.GetNews(id, 1, 24 * hotpage - 24, 24 * hotpage);
                List<News> totalNews2 = nservice.GetNews(id, 0, 0, 0);
                totalRecordWeb = totalNews2.Count;
            }
            ViewData["nlistHotWeb"] = nlistHotWeb;
            ViewData["nListWeb"] = nListWeb;
            ViewBag.totalRecordWeb = totalRecordWeb;
            return View();
        }
        [HttpGet]
        public ActionResult NewsLoadMore(int hotpage = 1)
        {
            NewsService nservice = new NewsService();

            int totalRecord = 0;
            List<News> totalNews = nservice.GetNews(0, 0, 0, 0);
            totalRecord = totalNews.Count;

            CategoryService cs = new CategoryService();

            ViewBag.totalRecord = totalRecord;

            ViewBag.hotpage = hotpage;



            //WEB

            int totalRecordWeb = 0;
            totalRecordWeb = totalNews.Count;

            List<News> nlistHotWeb = nservice.GetNews(0, 1, 24 * hotpage - 24, 24 * hotpage); //1: download

            ViewData["nlistHotWeb"] = nlistHotWeb;

            ViewBag.totalRecordWeb = totalRecordWeb;
            return View();
        }

    }
}
